package zuoye_3_10;

import java.util.Map;
import java.util.Scanner;
import java.util.function.Function;
import java.util.stream.Collectors;

//7.我们使用[0-9] [a-z][A-Z]范围内来表示字符串
//示例1：
//输入ppRYYGrrYBR2258
//p-2
////R-2
//Y-1
//G-1
////r-2
////R-2
//2-2
//5-1
////8-1
//B-1
//	YrR8RrY
////Y-2
////r-2
////R-2
////8-1
//输出：
//Yes 8
//
//
//	输入:ppRYYGrrYB225
//	YrR8RrY
//NO
public class Zuoye_7 {
	public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入第一个字符串：");
        String str1 = sc.nextLine();
        System.out.println("请输入第二个字符串：");
        String str2 = sc.nextLine();
        int remaining = isMatch(str1, str2);
        if (remaining >= 0) {
            System.out.println("Yes " + remaining);
        } else {
            System.out.println("No");
        }
    }

	 public static int isMatch(String str1, String str2) {
	        Map<Character, Long> map1 = getCharCount(str1);
	        Map<Character, Long> map2 = getCharCount(str2);
	        for (Map.Entry<Character, Long> entry : map2.entrySet()) {
	            if (!map1.containsKey(entry.getKey()) || map1.get(entry.getKey()) < entry.getValue()) {
	                return -1;
	            }
	            map1.put(entry.getKey(), map1.get(entry.getKey()) - entry.getValue());
	        }
	        long remaining = map1.values().stream().mapToLong(Long::longValue).sum();
	        return (int) remaining;
	    }

	    public static Map<Character, Long> getCharCount(String str) {
	        return str.chars()
	                .mapToObj(c -> (char) c)
	                .collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));
	    }
}
